# For the 2006 Seattle Mariners players below, enter these data into # a R data set, calculate each player's batting average (H/AB) and slugging # average (TB/AB), and print the results using mean(), summary(). Calculate the # mean batting average using Proc Means, and plot hits (H) versus at bats (AB) # using plot(). # Name AB H TB # Ichiro Suzuki 695 224 289 # Kenji Johjima 506 147 228 # Raul Ibanez 626 181 323 # Adrian Beltre 620 166 288 first=c('Ichiro', 'Kenji', 'Raul', 'Adrian') last=c('Suzuki','Johjima','Ibanez','Beltre') ab=c(695,506,626,620) h=c(224,147,181,166) tb=c(289,228,323,288) # can make a dataset with all these vectors (not always necessary) bball=data.frame(first,last,ab,h,tb) View(bball) # note that view starts with capital V bat=h/ab slug=tb/ab bb=data.frame(first,last,ab,h,tb,bat,slug) # this all could have been done in the first steps View(bb) # many ways to find the mean of a vector mean(bat) summary(bat) # or summary(bb) does the whole dataset # ... and more plot(ab,h); title('Hits vs. At Bats')